// Package expressinfo
// @Link  https://github.com/bufanyun/hotgo
// @Copyright  Copyright (c) 2025 HotGo CLI
// @Author  Ms <133814250@qq.com>
// @License  https://github.com/bufanyun/hotgo/blob/master/LICENSE
// @AutoGenerate Version 2.15.11
package expressinfo

import (
	"context"
	"hotgo/api/admin/expressinfo"
	"hotgo/internal/library/contexts"
	"hotgo/internal/model/input/expressinfoin"
	"hotgo/internal/service"
)

var (
	ExpressInfo = cExpressInfo{}
)

type cExpressInfo struct{}

// List 查看物流信息列表
func (c *cExpressInfo) List(ctx context.Context, req *expressinfo.ListReq) (res *expressinfo.ListRes, err error) {
	list, totalCount, err := service.ExpressinfoExpressInfo().List(ctx, &req.ExpressInfoListInp)
	if err != nil {
		return
	}

	if list == nil {
		list = []*expressinfoin.ExpressInfoListModel{}
	}

	res = new(expressinfo.ListRes)
	res.List = list
	res.PageRes.Pack(req, totalCount)
	return
}

// Export 导出物流信息列表
func (c *cExpressInfo) Export(ctx context.Context, req *expressinfo.ExportReq) (res *expressinfo.ExportRes, err error) {
	err = service.ExpressinfoExpressInfo().Export(ctx, &req.ExpressInfoListInp)
	return
}

// Edit 更新物流信息
func (c *cExpressInfo) Edit(ctx context.Context, req *expressinfo.EditReq) (res *expressinfo.EditRes, err error) {
	res = new(expressinfo.EditRes)
	res.Id, err = service.ExpressinfoExpressInfo().Edit(ctx, &req.ExpressInfoEditInp)
	return
}

// View 获取指定物流信息信息
func (c *cExpressInfo) View(ctx context.Context, req *expressinfo.ViewReq) (res *expressinfo.ViewRes, err error) {
	data, err := service.ExpressinfoExpressInfo().View(ctx, &req.ExpressInfoViewInp)
	if err != nil {
		return
	}

	res = new(expressinfo.ViewRes)
	res.ExpressInfoViewModel = data
	return
}

// Delete 删除物流信息
func (c *cExpressInfo) Delete(ctx context.Context, req *expressinfo.DeleteReq) (res *expressinfo.DeleteRes, err error) {
	err = service.ExpressinfoExpressInfo().Delete(ctx, &req.ExpressInfoDeleteInp)
	return
}

// StatusChange 修改物流信息状态
func (c *cExpressInfo) StatusChange(ctx context.Context, req *expressinfo.ExpressStatusChangeReq) (res *expressinfo.ExpressStatusChangeRes, err error) {
	userModel := contexts.GetUser(ctx)
	err = service.ExpressinfoExpressInfo().ToExpressed(ctx, &req.ExpressInfoChangeStatusInp, userModel)
	return
}
